/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package chameleon.view;

import chameleon.view.input.Input;
import chameleon.view.input.InputDecorator;
import chameleon.view.input.SmvFile;
import java.io.File;
import java.io.IOException;
import javax.imageio.IIOException;

/**
 *
 * @author simon
 */
public class InputFactory {

    //********************** ADDING ELEMENTS ********************************//

    /**
     * Add the file given on input to the input instance given on input
     *
     * @param nuSmv
     * @param input
     * @throws IOException
     * @return input
     */

    public static Input addSmvFile(File nuSmv, Input input) throws IOException{
        if (nuSmv.isFile() && nuSmv.exists()){
            if (!input.hasSmvFile() && correctExtension(".smv", nuSmv)){
                InputDecorator decoration = new SmvFile(nuSmv);
                input.addDecoration(decoration);
                return input;
            }
            else{
                if (input.hasSmvFile()){
                    throw new IOException("There is alread a Nusmv decoration");
                }
                else{
                    throw new IOException("Uncorrect extension");
                }
            }
        }
        else
            throw new IIOException("File doesn't exists");
    }

    //********************** DELETE ELEMENTS *******************************//
    
    public static void deleteAllDecorations(Input input){
        input.deleteAllDecoration();
    }

    //************************ QUESTIONS METHOD ****************************//
    
    private static boolean correctExtension (String extension, File file){
        String ext = file.getName().substring(file.getName().indexOf("." ));
        return ext.matches(extension);
    }
}
